home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Outbound.c
-
- Copyright (c) 1990-1, Thomas Knoll.
- Copyright (c) 1992-6, Adobe Systems Incorporated.
- All rights reserved.
-
- C source file for Outbound export example.
- */
-
- #if __MWERKS__
- #include <SetupA4.h> // A4-globals
- #include <A4Stuff.h> // A4-globals
- #endif
-
- #if defined(THINK_C) || defined(__MWERKS__)
- #define ENTRYPOINT main
- #endif
-
- #include "Outbound.h"
-
- Handle hDllInstance = NULL;
-
- /*****************************************************************************/
-
- void InitGlobals (GPtr globals);
- void DoPrepare (GPtr globals);
- void DoStart (GPtr globals);
- void DoContinue (GPtr globals);
- void DoFinish (GPtr globals);
- void DoInitialRect (GPtr globals);
- Boolean DoNextRect (GPtr globals);
- void DoExportRect (GPtr globals);
-
- /*****************************************************************************/
-
- /* All calls to the plug-in module come through this routine. It must be
- placed first in the resource. To achieve this, most development systems
- require that this be the first routine in the source. */
-
- #if MSWindows
- void ENTRYPOINT (short selector,
- ExportRecord *exportParamBlock,
- long *data,
- short *result)
- #else
- pascal void ENTRYPOINT (short selector,
- ExportRecord *exportParamBlock,
- long *data,
- short *result)
- #endif
- {
-
- Globals globalValues;
- GPtr globals = &globalValues;
-
- #if __MWERKS__
- EnterCodeResource(); // A4-globals
- #endif
-
- if (!*data)
- {
-
- InitGlobals (globals);
-
- *data = (long) NewHandle (sizeof (Globals));
-
- if (!*data)
- {
- *result = memFullErr;
- return;
- }
-
- ** (GHdl) *data = globalValues;
-
- }
-
- globalValues = ** (GHdl) *data;
-
- gStuff = exportParamBlock;
- gResult = noErr;
-
- switch (selector)
- {
-
- case exportSelectorAbout:
- DoAbout (globals);
- break;
-
- case exportSelectorPrepare:
- DoPrepare (globals);
- break;
-
- case exportSelectorStart:
- DoStart (globals);
- break;
-
- case exportSelectorContinue:
- DoContinue (globals);
- break;
-
- case exportSelectorFinish:
- DoFinish (globals);
- break;
-
- default:
- gResult = exportBadParameters;
-
- }
-
- *result = gResult;
- ** (GHdl) *data = globalValues;
-
- #if __MWERKS__
- ExitCodeResource(); // A4-globals
- #endif
-
- }
-
- /*****************************************************************************/
-
- void InitGlobals (GPtr globals)
- {
-
- gQueryForParameters = true;
-
- }
-
- /*****************************************************************************/
-
- /* Prepare to export an image. If the plug-in module needs only a limited
- amount of memory, it can lower the value of the 'maxData' field. */
-
- void DoPrepare (GPtr globals)
- {
-
- if (gStuff->maxData > 0x80000)
- gStuff->maxData = 0x80000;
-
- }
-
- /*****************************************************************************/
-
- /* Requests pointer to the first part of the image to be filtered. */
-
- void DoStart (GPtr globals)
- {
-
- FileHandle fRefNum;
-
- /* This plug-in does not support bitmap images */
-
- if (gStuff->imageMode == plugInModeBitmap)
- {
- gResult = exportBadMode;
- return;
- }
-
- /* check with the scripting system whether to pop our dialog */
- gQueryForParameters = true; // assume yes
- gAliasHandle = nil; // no handle, yet
-
- ReadScriptParams (globals);
-
- if (!QueryForExportFile (globals)) return;
-
- if (!CreateExportFile (globals, &fRefNum)) return;
-
- (void) WriteExportFile (globals, fRefNum);
-
- (void) CloseExportFile (globals, fRefNum);
-
- MarkExportFinished (gStuff);
-
- }
-
- /*****************************************************************************/
-
- /* Filters the area and requests the next area. */
-
- void DoContinue (GPtr globals)
- {
-
- /* We shouldn't get here because we did all of the work during the
- start phase, but we add some code just in case. */
-
- MarkExportFinished (gStuff);
-
- gResult = userCanceledErr;
-
- }
-
- /*****************************************************************************/
-
- /* This routine will always be called if DoStart does not return an error
- (even if DoContinue returns an error or the user aborts the operation).
- This allows the module to perform any needed cleanup. None is required
- in this example. */
-
- void DoFinish (GPtr globals)
- {
- WriteScriptParams (globals);
- }
-
- /*****************************************************************************/
-
- #define RANGE_ITER(lower,upper,first,last,step) \
- for (lower = (first); \
- (upper = (((lower) + (step) < (last)) ? (lower) + (step) : (last))), \
- lower < (last); \
- lower = upper)
-
- /*****************************************************************************/
-
- Boolean WriteExportFile (GPtr globals, FileHandle fRefNum)
- {
- /* We write out the file as an interleaved raw file. */
-
- /* We need to figure out how many rows to write at one time. */
-
- long chunk = gStuff->maxData / gStuff->imageSize.h / gStuff->planes;
-
- ExportRegion region;
-
- region.rect.left = 0;
- region.rect.right = gStuff->imageSize.h;
- region.loPlane = 0;
- region.hiPlane = gStuff->planes - 1;
-
- RANGE_ITER (region.rect.top, region.rect.bottom,
- 0, gStuff->imageSize.v, chunk)
- {
-
- int16 row;
- long rowCount = gStuff->imageSize.h * (long) gStuff->planes;
- void *data = 0;
- int32 rowBytes = 0;
- unsigned8 *rowData;
-
- if (!TSC (TestAbort ())) return FALSE;
-
- if (!TSR (FetchData (gStuff, ®ion, &data, &rowBytes))) return FALSE;
-
- for (row = region.rect.top, rowData = (unsigned8 *) data;
- row < region.rect.bottom;
- ++row, rowData += rowBytes)
- {
-
- long count = rowCount;
-
- UpdateProgress (row, gStuff->imageSize.v);
-
- if (!TSC (TestAbort ())) return FALSE;
-
- if (!TSR (FSWrite (fRefNum, &count, rowData))) return FALSE;
-
- }
-
- }
-
- return TRUE;
-
- }
-
- /*****************************************************************************/
-
- OSErr FetchData (ExportRecord *stuff,
- ExportRegion *region,
- void **data,
- int32 *rowBytes)
- {
-
- OSErr result;
-
- if (!WarnHostAdvanceStateAvailable (stuff->advanceState, hDllInstance))
- return userCanceledErr;
-
- stuff->theRect = region->rect;
- stuff->loPlane = region->loPlane;
- stuff->hiPlane = region->hiPlane;
-
- result = (*(stuff->advanceState)) ();
-
- if (result != noErr)
- {
- *data = NULL;
- *rowBytes = 0;
- }
- else
- {
- *data = stuff->data;
- *rowBytes = stuff->rowBytes;
- }
-
- return result;
-
- }
-
- /*****************************************************************************/
-
- void MarkExportFinished (ExportRecord *stuff)
- {
-
- PISetRect (&stuff->theRect, 0, 0, 0, 0);
-
- }
-
- /*****************************************************************************/
-
-
-
-
-
-